import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;


public class DataPoint {

	private int id;
	private double previousWindSpeed;
	private double nextWindSpeed;
	private Date forecastedDateTime;
	private Date forecastDate;
	private double windSpeed;
	//There are 6 power outputs for every forecast point for now
	private ArrayList<Double> powerOutputList;
	
	public DataPoint(int id, Date forecastedDateTime, Date forecastDate, double windSpeed) {
		super();
		this.id = id;
		this.forecastedDateTime = forecastedDateTime;
		this.forecastDate = forecastDate;
		this.windSpeed = windSpeed;
		powerOutputList=new ArrayList<Double>();
	}
	/**
	 * id- sequential id of the datapoint
	 * @return id
	 */
	public int getId() {
		return id;
	}
	/**
	 * Return the read wind speed from spreadsheet
	 * @return windspeed
	 */
	public double getWindSpeed() {
		return windSpeed;
	}
	/**
	 * Average all the elements in poweroutput list and return it
	 * @return average power output of the hour
	 */
	public double getAvgPowerOutput() {
		double totalPower = 0.0;
		for (double partialPower : powerOutputList) {
			totalPower += partialPower;
		}
		if (powerOutputList.size() != 0) {
			return totalPower / powerOutputList.size();
		} else {
			return 0.0;
		}
	}
	/**
	 * Sort the power entries and return the median power
	 * @return median power output in the hour
	 */
	public double getMedianPowerOutput() {
		if (powerOutputList.size() != 0) {
			Collections.sort(powerOutputList);

			if (powerOutputList.size() % 2 == 1)
				return powerOutputList.get((powerOutputList.size() + 1) / 2 - 1);
			else {
				double lower = powerOutputList.get(powerOutputList.size() / 2 - 1);
				double upper = powerOutputList.get(powerOutputList.size() / 2);

				return (lower + upper) / 2.0;
			}
		} else {
			return 0;
		}
	}
	/**
	 * 
	 * @return the list of power output values in the hour
	 */
	public ArrayList<Double> getPowerOutputList() {
		return powerOutputList;
	}
	/**
	 * add a poweroutput value from the spreadsheet as its read
	 * @param powerOutput
	 */
	public void addToPowerOutputList(Double powerOutput){
		powerOutputList.add(powerOutput);
	}
	/**
	 * Unused
	 * @return
	 */
	public double getPreviousWindSpeed() {
		return previousWindSpeed;
	}
	/**
	 * unused
	 * @param previousWindSpeed
	 */
	public void setPreviousWindSpeed(double previousWindSpeed) {
		this.previousWindSpeed = previousWindSpeed;
	}
	public double getNextWindSpeed() {
		return nextWindSpeed;
	}
	public void setNextWindSpeed(double nextWindSpeed) {
		this.nextWindSpeed = nextWindSpeed;
	}
	public Date getForecastedDateTime() {
		return forecastedDateTime;
	}
	public Date getForecastDate() {
		return forecastDate;
	}

	
}
